package com.cimstech.model;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "node")
public class NodeInfo {

    private String id;

    private String name;

    private String type;

    private ArrayList<NodeInfo> nodes;

    private boolean isOpen = false;

    public NodeInfo() {
    }

    public NodeInfo(String name, String id, String type) {
        this.name = name;
        this.id = id;
        this.type = type;
    }

    @XmlElement(name = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @XmlElement(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlElement(name = "type")
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @XmlElement(name = "nodes")
    public ArrayList<NodeInfo> getNodes() {
        return nodes;
    }

    public void setNodes(ArrayList<NodeInfo> nodes) {
        this.nodes = nodes;
    }

    @XmlElement(name = "isOpen")
    public boolean isOpen() {
        return isOpen;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("{\"id\":\"").append(id).append("\",\"name\":\"").append(name).append("\",\"type\":\"").append(type).append("\",\"nodes\":[");
        if (nodes != null) {
            int i = 1;
            for (NodeInfo nod : nodes) {
                if (i < nodes.size()) {
                    sb.append(nod.toString()).append(",");
                } else {
                    sb.append(nod.toString());
                }
                i++;
            }
        }
        sb.append("],\"isOpen\":").append(isOpen).append("}");
        return sb.toString();
    }
}
